package com.ruoyi.web.controller.dr;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dr.domain.DrOwnerUnion;
import com.ruoyi.dr.service.IDrOwnerUnionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;

/**
 * 归属信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-14
 */
@RestController
@RequestMapping("/dr/ownerUnion")
public class DrOwnerUnionController extends BaseController
{
    @Autowired
    private IDrOwnerUnionService drOwnerUnionService;

    /**
     * 查询归属信息列表
     */
//    @PreAuthorize("@ss.hasPermi('common:union:list')")
    @GetMapping("/list")
    public AjaxResult list(DrOwnerUnion drOwnerUnion) {
        List<DrOwnerUnion> list = drOwnerUnionService.selectDrOwnerUnionList(drOwnerUnion);
        return success(list);
    }

    /**
     * 导出归属信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:union:export')")
    @Log(title = "归属信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrOwnerUnion drOwnerUnion)
    {
        List<DrOwnerUnion> list = drOwnerUnionService.selectDrOwnerUnionList(drOwnerUnion);
        ExcelUtil<DrOwnerUnion> util = new ExcelUtil<DrOwnerUnion>(DrOwnerUnion.class);
        util.exportExcel(response, list, "归属信息数据");
    }

    /**
     * 获取归属信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:union:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(drOwnerUnionService.selectDrOwnerUnionById(id));
    }

    /**
     * 新增归属信息
     */
//    @PreAuthorize("@ss.hasPermi('system:union:add')")
    @Log(title = "归属信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrOwnerUnion drOwnerUnion)
    {
        return toAjax(drOwnerUnionService.insertDrOwnerUnion(drOwnerUnion));
    }

    /**
     * 修改归属信息
     */
//    @PreAuthorize("@ss.hasPermi('system:union:edit')")
    @Log(title = "归属信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrOwnerUnion drOwnerUnion)
    {
        return toAjax(drOwnerUnionService.updateDrOwnerUnion(drOwnerUnion));
    }

    /**
     * 删除归属信息
     */
//    @PreAuthorize("@ss.hasPermi('system:union:remove')")
    @Log(title = "归属信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(drOwnerUnionService.deleteDrOwnerUnionByIds(ids));
    }



    @Log(title = "归属信息导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<DrOwnerUnion> util = new ExcelUtil<>(DrOwnerUnion.class);
        List<DrOwnerUnion> sellDetails = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = drOwnerUnionService.importOwnerUnion(sellDetails, operName);
        return success(message);
    }



    /**
     * 获取归属下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(DrOwnerUnion ownerUnion)
    {
        List<DrOwnerUnion> ownerUnions = drOwnerUnionService.selectDrOwnerUnionList(ownerUnion);
        return success(drOwnerUnionService.buildOwnerUnionTree(ownerUnions));
    }
}
